package com.sxhuayuan.parking.dao;

import com.sxhuayuan.parking.entity.Salesman;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.sxhuayuan.parking.entity.Agent;

import java.util.List;

public interface AgentDao extends BaseDao<Agent, Long> {

	Agent findByUsername(String username);

	/** hypk_admin_role删除 */
	@Modifying
	@Query(value = "delete from hypk_agent_role where agents_id = ?1", nativeQuery = true)
	void deletaAgentRole(Long id);

	@Query(value = "select * from hypk_agent where access_token = ?1", nativeQuery = true)
	Agent findByAccessToken(String accessToken);

	@Query("select count(g.id) from Agent g join AgentRelation a on g.id=a.child.id where a.parent=?1")
	Long countByAgent(Agent parent);

	/** 根据业务员获取代理列表 */
    List<Agent> findBySalesmanId(Long salesmanId);
}
